import React, { ReactElement, useState, useEffect } from 'react'
import { Input, Button } from 'antd'
import { postLogin } from '../../utils/Ajax/api'
interface Props {
  location: any,
  history: any
}
export default function Login(props: Props): ReactElement {
  console.log(props, 'props')
  const [user_name, setUsername] = useState('')
  const [user_pwd, setPassword] = useState('')

  useEffect(() => {
    const mylogin = () => {
      // postLogin({ username, password }).then(res => {
      //   console.log(res, 'res')
      // })
    }
  }, [])
  return (
    <div>
      账号：<Input value={user_name} onChange={(e) => {
        setUsername(e.target.value)
      }} />
      密码：<Input value={user_pwd} onChange={(e) => {
        setPassword(e.target.value)
      }} />
      <Button onClick={() => {
        postLogin({ user_name, user_pwd }).then(res => {
          console.log(res, 'res')
          if (res.data.code === 1) {
            window.sessionStorage.setItem('token', res.data.token)
            props.history.push('/homeIndex/test')
          }
        })
      }}>登陆</Button>

    </div>
  )
}
